import {
    getSearchMovieid,postSelectMovieAPI
  } from "../../api/userinfo";
const movie:any = {
    state: {
      movieInfo:{
      }, 
      movieList:{

      },
      movieTopList:[{
      }],
      expectMovie:[{

      }],
      expectTopMovie:[{
        
      }]
    },
  
    mutations: {
      //保存影片基本信息
      SET_MOVIEINFO(state: any, value: any) {
        state.movieInfo = value;
      },
      //保存已上映影片
      SET_MOVIELIST(state: any, value: any){
        state.movieList=value
      },
      //保存排行榜影片
      SET_MOVIETOP(state: any, value: any){
        state.movieTopList=value
      },
      //保存未上映的影片
      SET_EXPECTMOVIE(state: any, value: any){
          state.expectMovie=value;
      },
      //保存期待排行榜影片
      SET_EXPECTMOVIETOP(state: any, value: any){
        state.expectTopMovie=value;
      }
    },
    actions: {
        async SET_MOVIEINFO(content: any,id: any){
            await getSearchMovieid({mid:id}).then((res: any)=>{
                content.commit("SET_MOVIEINFO",...res.data);
            })
        },
        async SET_MOVIELIST(content:any){
          await postSelectMovieAPI().then((res:any)=>{
            let movielist=[] as any;
            let expectlist=[] as any;
            res.data.filter((item:any)=>{
              if(item.state){
                movielist.push(item)
              }
              else if(!item.state){
                expectlist.push(item)
              }
            })
            content.commit("SET_MOVIELIST",movielist);
            content.commit("SET_EXPECTMOVIE",expectlist);
            
          })
        },
    },
  };
 
  export default movie;